package main

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
)

type Config struct {
	Addr    string `json:"addr"` // "TCP address to listen to"
	BidPath string `json:"bid_path"`

	// s3 配置
	S3Accessid string `json:"s3Accessid"`
	S3Secret   string `json:"s3Secret"`
	S3Bucket   string `json:"s3Bucket"`
	S3Region   string `json:"s3Region"`

	// 日志
	WriteLen   bool `json:"write_len"`
	WriteNL    bool `json:"write_nl"`
	LogMaxLine int  `json:"log_max_line"`

	// ssp bid
	Ssps map[string]string `json:"ssp_bidpath"`
	//	Sspbidpath int `json:"ssp_bidpath"`
}

var config = Config{
	Ssps: make(map[string]string),
}

/*
"ssp-bidpath": {
    "bidswitch_test":"/bidswitch_test",
    "smartrtb_test":"/smartrtb_test"
  },
*/

// o : map[string]value
func printErr(e error, o interface{}) {

	log.Print("err:", e, ";")

	switch o.(type) {
	case map[string]interface{}:
		for k, v := range o.(map[string]interface{}) {
			log.Print(k, ":", v, ";")
		}
	}
}

func getErrs(k string, v interface{}) map[string]interface{} {
	return map[string]interface{}{k: v}
}

func main() {

	log.SetFlags(log.Lshortfile | log.LstdFlags)

	bytes, err := ioutil.ReadFile("./ssps.json") //解析不了 map[stirng]string
	if err != nil {
		printErr(err, getErrs("bytes len", len(bytes)))
	}

	//	config := Config{Ssps: make(map[string]string, 2)}
	fmt.Println("map len:", len(config.Ssps))

	//	config.Ssps = make{map[string]string}

	err = json.Unmarshal(bytes, &config)
	if err != nil {
		printErr(err, getErrs("bytes len", len(bytes)))
	}

	fmt.Println(config)

	/*
		newConf, err := conf.NewConf("ssps.json")
		if err != nil {
			printErr(err, nil)
		}


		fmt.Println(newConf)*/
}
